﻿// TabTipNotification.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include <Windows.h>
#include "..\TabTipNotification.h"

BOOL ShelRunTabTipWindow()
{
    wchar_t path[MAX_PATH];
    GetModuleFileName(NULL, path, MAX_PATH);        //获取到完整路径如：E:\Tools\qq.exe                                               //截取路径E:\Tools
    wchar_t* pName = wcsrchr(path, L'\\');
    *pName = L'\0';

    std::wstring cmdPath = path;
    if (cmdPath.size() == 0)
    {
        cmdPath = L"TabTipWindow.exe";
    }
    else {
        cmdPath += L"\\TabTipWindow.exe";
    }

    SHELLEXECUTEINFOW sei = { sizeof(SHELLEXECUTEINFO) };
    sei.lpFile = cmdPath.c_str();
    sei.lpVerb = NULL;// L"runas";
    sei.fMask = SEE_MASK_NOCLOSEPROCESS;
    sei.nShow = SW_SHOW;

    std::wstring cmd = L"";
    sei.lpParameters = NULL;

    BOOL res = ::ShellExecuteEx(&sei);
    if (res) {
        printf("%S success", cmd.c_str());
    }
    else {
        printf("%S failed, err: %lu", cmd.c_str(), GetLastError());
    }
    return res;
}

int main()
{
    ShelRunTabTipWindow();
    Sleep(1000);

    std::cout << "Start Monitor System Input State...\n";
    if (!CTabTipNotification::getSingletonPtr())
    {
        new CTabTipNotification();
    }
    CTabTipNotification::getSingletonPtr()->StartListenNotification();

    getchar();

    if (CTabTipNotification::getSingletonPtr())
    {
        CTabTipNotification::getSingletonPtr()->StopListenNotification();
    }

    std::cout << "Stop Monitor System Input State...\n";
    getchar();
}
